layui.use(['layer', 'table','form'], function () {
    var table = layui.table //表格
        , $ = layui.$;
    $('.logSearch').on('click', function () {
        renderLogTable();
    })
    function renderLogTable() {
        var service = $("[name='log-service']").val();
        var state = $("[name='state']").val();
        table.render({
            elem: '#logTable'
            , url: '/groovyLog/search'
            , where: { 'service': service,'state':state}
            , parseData: function (res) {
                return {
                    "code": res.code==200?0:res.code,
                    "msg": res.msg,
                    "count": res.total,
                    "data": res.rows
                };
            }
            , cols: [[
                { field: 'groovyService', title: '访问路径', align: 'center', width: '20%' }
                , { field: 'code', title: '状态码', align: 'center', width: '5%',templet: generateFunc}
                , { field: 'msg', title: '返回信息', align: 'center', width: '10%' }
                , { field: 'className', title: '接口类', align: 'center', width: '15%' }
                , { field: 'params', title: '访问参数', align: 'center', width: '10%' }
                , { field: 'result', title: '返回结果', align: 'center', width: '30%' }
                , { field: 'logTime', title: '操作时间', align: 'center', width: '10%' }
            ]]
            , page: true
        });
    }
    renderLogTable();
});
function generateFunc(data) {
    var htmlStr = "";
    if (data.code == 200) {
        htmlStr += '<font color="green">'+data.code+'</font>';
    } else if (data.code == 400) {
        htmlStr += '<font color="red">'+data.code+'</font>';
    } else {
        htmlStr += '<font color="gray">'+data.code+'</font>';
    }
    return htmlStr;
}
